package com.CST.controller;

import com.CST.common.api.Response;
import com.CST.entity.AccvouchWorkloadDTO;
import com.CST.service.impl.IAccvouchWorkloadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "凭证分录数")
@RequestMapping("/Accvouch")
public class AccvouchController {

    @Autowired
    private IAccvouchWorkloadService accvouchService;

    @PostMapping("/getAccvouchWorkload")
    @ApiOperation("获取凭证分录数")
    public Response getAccvouchWorkload(@RequestBody AccvouchWorkloadDTO entity){
        if(entity.getStartDate().isEmpty() || entity.getEndDate().isEmpty())
        {
            return Response.error("日期错误");
        }
        entity.setStartDate(entity.getStartDate().replace("-",""));
        entity.setEndDate(entity.getEndDate().replace("-",""));
        return accvouchService.getAccvouchWorkload(entity);
    }

    @PostMapping("/exportExcel")
    @ApiOperation("科凭证分录数下载")
    public void exportExcel(HttpServletResponse response, @RequestBody AccvouchWorkloadDTO dto) throws Exception {
        accvouchService.exportExcel(response, dto);
    }
    
}
